package cn.itcast.java.serialize;

import java.io.*;

/**
 * Author itcast
 * Date 2021/10/13 17:54
 * Desc TODO
 */
public class SerializeStudent {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 将 Student 写入到文件中
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("data/student.txt"));
        Student xiaobo = new Student("周晓波", 20);
        oos.writeObject(xiaobo);
        // 从文件中读已经被序列化的文件并反序列化成 Student 对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data/student.txt"));
        Student s = (Student) ois.readObject();
        System.out.println(s);
    }
}
